﻿/*
 <appSettings>
		<add key="LoggerName" value="BlogLogger"/>
		<add key="NumberOfResultsPerPage" value="10"/>
        <add key="DefaultDb" value="MySql"/>
 </appSettings>
 */

using System.Configuration;

namespace BestEasyCMS.Framework.Configuration
{
    public class WebConfigApplicationSettings : IApplicationSettings
    {
        public string LoggerName
        {
            get { return ConfigurationManager.AppSettings[AppSettingKeyHelper.LoggerName]; }
        }

        public string NumberOfResultsPerPage
        {
            get { return ConfigurationManager.AppSettings[AppSettingKeyHelper.NumberOfResultsPerPage]; }
        }

        public string DefaultDb
        {
            get { return ConfigurationManager.AppSettings[AppSettingKeyHelper.DefaultDb]; }
        }

        public string Domain { get { return ConfigurationManager.AppSettings[AppSettingKeyHelper.Domain]; } }
        public string DomainAdmin { get { return ConfigurationManager.AppSettings[AppSettingKeyHelper.DomainAdmin]; } }

        public void UpdateAppSettingValue(string key, string value)
        {
            System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

            config.AppSettings.Settings[key].Value = value;

            config.Save();

            ConfigurationManager.RefreshSection("appSettings");
        }
        public void AddAppSettingValue(string key, string value)
        {
            System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

            config.AppSettings.Settings.Add(key, value);

            config.Save();

            ConfigurationManager.RefreshSection("appSettings");
        }
    }

}
